package chapter03;

public class Test05_Package {
    public static void main(String[] args) {
        Teacher t1 = new Teacher();
        t1.setAge(50);
        System.out.println(t1.getAge());
        t1.setName("张三");
        t1.introduce();
    }
}
class Teacher{
    private int age;
    private String name;
    void introduce(){
        System.out.println("名字："+name);
        System.out.println("年龄："+age);
    }
    //属性 通过方法进行赋值和取值
    public int getAge(){
        return age;
    }
    public void setAge(int num){
        //就可以限制年龄
        if(num<0||num>120){
            System.out.println("年龄不合理，请重新赋值");
        }
        age = num;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}
